/**
 * 陈皓
 *
 * 2017年12月19日
 */
package com.bjc.loginController;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.alibaba.fastjson.JSON;
import com.bjc.base.core.MyException;
import com.bjc.core.bean.response.EmployeeVO;
import com.bjc.core.tool.service.IRedisService;

/**
 * @author Administrator
 *
 */
public class BaseAction {

	@Autowired
	private IRedisService iRedisService;
	
	/*
	 * 获取登录人的用户信息
	 */
	public EmployeeVO getEmployeeVO() {

		ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = attributes.getRequest();
		String bjcToken = request.getHeader("bjcToken");
		if (StringUtils.isEmpty(bjcToken)) {
			throw new MyException("bjcToken不能为空");
		}
		String bjcTokens = "";
		try {
			bjcTokens = URLDecoder.decode(bjcToken, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		String user = iRedisService.get(bjcTokens);
		EmployeeVO employeeVO = null;
		if (StringUtils.isNotEmpty(user)) {
			employeeVO = JSON.parseObject(user, EmployeeVO.class);
		}
		return employeeVO;
	}
}
